#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}

rm -rf ~/Godot
mkdir -p ~/Godot
cd ~/Godot
wget -O ~/Godot/godot.zip https://github.com/hiulit/Unofficial-Godot-Engine-Raspberry-Pi/releases/download/v1.5.0/godot_3.3.3-stable_rpi4.zip || error "failed to download!"
unzip $(pwd)/godot.zip
rm -f $(pwd)/godot.zip

rm -f godot_3.3.3-stable_rpi4_headless_lto.bin
rm -f godot_3.3.3-stable_rpi4_server_lto.bin

echo "[Desktop Entry]
Name=Godot Engine
Comment=Best Opensource Game Engine 
Exec=bash -c 'cd $HOME/Godot ; $HOME/Godot/godot_3.3.3-stable_rpi4_editor_lto.bin'
Icon=$(dirname $0)/icon-64.png
Terminal=false
Type=Application
Categories=Development;
StartupNotify=true" > ~/.local/share/applications/godot-engine.desktop
